package com.colortea.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Repository;

import com.colortea.dao.RoleMDao;
import com.colortea.entity.RoleM;
import com.colortea.dao.impl.RoleMDaoImpl;


@Repository("roleMDao")
public class RoleMDaoImpl extends BaseTDaoImpl<RoleM> implements RoleMDao {
private static final Logger log = LoggerFactory.getLogger(RoleMDaoImpl.class);

	
	public int delRoleM(final String[] strs) {
		log.debug("delRoleM");
		try {

			final String queryString = "delete from RoleM as rm where rm.id=:id";
			Query query = this.getSessionFactory().openSession().createQuery(queryString);
			int i = 0;
			for (String s : strs) {
				query.setParameter("id", s);
				i = query.executeUpdate();
				i++;
			}
			if (strs.length == i) {
				return i;
			} else {
				return 0;
			}
		} catch (RuntimeException re) {
			log.error("delRoleM failed", re);
			throw re;
		}
	}

	public List<RoleM> findAllRoleM() {
		log.debug("findAllRoleM");
		try {
			String queryString = "from RoleM";
			Query createQuery = this.getSessionFactory().openSession().createQuery(queryString);
			
			List<RoleM> list =createQuery.list();
			return list;
		} catch (RuntimeException re) {
			log.error("findAllRoleM error", re);
			throw re;
		}
	}

	public RoleM findRoleMById(String id) {
		log.debug("findRoleMById");
		try {
			RoleM instance = (RoleM) this.getSessionFactory().openSession().get(RoleM.class, id);
			return instance;
		} catch (RuntimeException re) {
			log.error("findModuleMById failed", re);
			throw re;
		}
	}

	public void updateRoleM(RoleM rm) {
		log.debug("updateRoleM");
		try {
			this.getSessionFactory().openSession().update(rm);;
		} catch (RuntimeException re) {
			log.error("updateRoleM failed", re);
			throw re;
		}
	}

	
	


}